package com.sacodemel.financeiro.persistencia.dao.impl;

import com.sacodemel.financeiro.modelo.dto.InvestimentoDTO;

import com.sacodemel.financeiro.persistencia.dao.IInvestimentoDAO;
import com.sacodemel.financeiro.util.Constantes;
import java.util.List;

import org.hibernate.Session;


public class InvestimentoDAO extends BaseDAO<InvestimentoDTO> implements IInvestimentoDAO{


        public InvestimentoDAO() {
		super(InvestimentoDTO.class);
		
	}
    
	public List<InvestimentoDTO> obterListaInvestimentos() throws Exception {
		
		Session session = null;
		try {
			session = getSession();
                        
                        session.beginTransaction();
                        
			List<InvestimentoDTO> obj = (List<InvestimentoDTO>) session.createQuery(
				" select new " + InvestimentoDTO.class.getCanonicalName() +  "(r.investidor.nome, sum(r.valor)) " +
                                " from RegistroCaixa r " +
                                "  join  r.investidor  " +
                                " where r.status = '"+Constantes.STATUS_ATIVO+"' " +
                                " group by r.investidor.nome ").list();
			
                        
                        
			return obj;
			
		} catch (Exception e) {
			throw e;
		} finally {
			close(session);
		}
		
	}

 

}
